package com.zt.chatglm.domain.chat.model;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;

/**
 * @author: zt
 * @Description: 消息携带的标识，如果是role是user/system则是文本，如果是role是assistant则是需要携带上下文消息
 * @create: 2024-05-20 16:26
 */

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Prompt {
    private String role;
    private String content;

    public static PromptBuilder builder() {
        return new PromptBuilder();
    }

    public static class PromptBuilder {
        private String role;
        private String content;

        PromptBuilder() {
        }

        public PromptBuilder role(String role) {
            this.role = role;
            return this;
        }

        public PromptBuilder content(String content) {
            this.content = content;
            return this;
        }

        public PromptBuilder content(Content content) {
            this.content = JSON.toJSONString(content);
            return this;
        }

        public Prompt build() {
            return new Prompt(this.role, this.content);
        }

        @Override
        public String toString() {
            return "ChatCompletionRequest.Prompt.PromptBuilder(role=" + this.role + ", content=" + this.content + ")";
        }
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class Content {
        private String type = Type.text.code;
        private String text;
        @JsonProperty("image_url")
        private ImageUrl imageUrl;

        @Getter
        @AllArgsConstructor
        public static enum Type {
            text("text", "文本"),
            image_url("image_url", "图"),
            ;
            private final String code;
            private final String info;
        }

        @Data
        @Builder
        @NoArgsConstructor
        @AllArgsConstructor
        public static class ImageUrl {
            private String url;
        }

    }
}
